<?php


namespace app\common\model;


use think\Db;
use think\Model;
use think\Request;

class Product extends Model
{
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    // 追加属性
    protected $append = [

    ];

    /**
     * 获取列表信息
     * @param array $where
     * @param array
     * @return string
     */
    static public function getList($where = [],$field="*", $sort = "id desc", $limit = 10,$page = 1)
    {
        $list = self::where($where)
//            ->with(['category'])
            ->order($sort)
            ->field($field)
            ->paginate($limit,false,['page' => $page]);
 
        return $list;
    }

    /**
     * 获取信息
     * @param array $where
     * @param array
     * @return string
     */
    static public function getInfo($where = [],$field = "")
    {
        return self::where($where)
//            ->with(['category'])
            ->where($where)
            ->field($field)
            ->find();

    }

    public function getImageAttr($value, $data)
    {
        $request = Request::instance();
        $domain = $request->domain();
        return  $domain . $value;
    }
}